package com.liwalla.domain;

import com.liwalla.domain.Vacine;
import java.util.List;
import java.util.Random;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

privileged aspect VacineDataOnDemand_Roo_DataOnDemand {
    
    declare @type: VacineDataOnDemand: @Component;
    
    private Random VacineDataOnDemand.rnd = new java.security.SecureRandom();
    
    private List<Vacine> VacineDataOnDemand.data;
    
    public Vacine VacineDataOnDemand.getNewTransientVacine(int index) {
        com.liwalla.domain.Vacine obj = new com.liwalla.domain.Vacine();
        obj.setDescription("description_" + index);
        obj.setName("name_" + index);
        return obj;
    }
    
    public Vacine VacineDataOnDemand.getSpecificVacine(int index) {
        init();
        if (index < 0) index = 0;
        if (index > (data.size()-1)) index = data.size() - 1;
        Vacine obj = data.get(index);
        return Vacine.findVacine(obj.getId());
    }
    
    public Vacine VacineDataOnDemand.getRandomVacine() {
        init();
        Vacine obj = data.get(rnd.nextInt(data.size()));
        return Vacine.findVacine(obj.getId());
    }
    
    public boolean VacineDataOnDemand.modifyVacine(Vacine obj) {
        return false;
    }
    
    @Transactional(propagation = Propagation.REQUIRES_NEW)
    public void VacineDataOnDemand.init() {
        if (data != null) {
            return;
        }
        
        data = com.liwalla.domain.Vacine.findVacineEntries(0, 10);
        if (data == null) throw new IllegalStateException("Find entries implementation for 'Vacine' illegally returned null");
        if (data.size() > 0) {
            return;
        }
        
        data = new java.util.ArrayList<com.liwalla.domain.Vacine>();
        for (int i = 0; i < 10; i++) {
            com.liwalla.domain.Vacine obj = getNewTransientVacine(i);
            obj.persist();
            data.add(obj);
        }
    }
    
}
